package com.yoda.mall.admin.controller;

import com.yoda.mall.admin.service.AdvertiseService;
import com.yoda.mall.model.entity.sms.FlashPromotionSession;
import com.yoda.mall.model.entity.sms.HomeAdvertise;
import com.yoda.mall.model.vo.FlashPromotionSessionVo;
import com.yoda.mall.model.vo.PageResult;
import com.yoda.mall.model.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@RestController
@RequestMapping("/home/advertise")
public class AdvertiseController {
    @Autowired
    private AdvertiseService advertiseService;

    //添加广告
    @PostMapping("create")
    public R createAdvertise(@RequestBody HomeAdvertise homeAdvertise){
        advertiseService.createAdvertise(homeAdvertise);
        return R.success();
    }

    //删除广告
    @PostMapping("delete")
    public R deleteAdvertise(@RequestParam List<Long> ids){
        advertiseService.deleteAdvertise(ids);
        return R.success();
    }

    //分页查询广告
    @GetMapping("list")
    public R advertiseList(LocalDateTime endTime,String name,Integer type,Integer pageNum,Integer pageSize){
        PageResult<HomeAdvertise> pageResult = advertiseService.advertiseList(endTime,name,type,pageNum,pageSize);
        return R.success(pageResult);
    }

    //修改上下线状态
    @PostMapping("update/status/{id}")
    public R updateAdvertiseStatus(Integer status,@PathVariable Long id){
        advertiseService.updateAdvertiseStatus(id,status);
        return R.success();
    }

    //修改广告
    @PostMapping("update/{id}")
    public R updateAdvertise(@RequestBody HomeAdvertise homeAdvertise,@PathVariable Long id){
        advertiseService.updateAdvertise(id,homeAdvertise);
        return R.success();
    }

    //获取广告详情
    @GetMapping("{id}")
    public R getAdvertise(@PathVariable Long id){
        HomeAdvertise homeAdvertise = advertiseService.getAdvertise(id);
        return R.success(homeAdvertise);
    }
}
